<?php
namespace Admin\Controller;
class ProductController extends BaseController{
	
	function add(){
		$typeOb=D('Type');
		$optionStr=$typeOb->showOption();
		$this->assign('optionstr',$optionStr);
		$this->display();
	}
	function save(){
		//调用M层
		//数据处理
		$type=$_POST['type'];
		unset($_POST['type']);
		$arr=explode("|",$type);
		$_POST['typefid']=$arr[0];
		$_POST['typeid']=$arr[1];
		$_POST['addtime']=time();
		//使用方法Model->data(数据)//Model->add()
		$newsOb=D('News');
		$re=$newsOb->data($_POST)
			       ->add();
		if($re){
			$this->success("添加成功。",U("Admin/News/oper"));
		}else{
			$this->error("添加失败",U("Admin/News/add"));
		}
		
	}
	function update(){
		$id=(int)$_GET['id'];
		$newsOb=D("News");
		$arr=$newsOb->where("id=$id")
			        ->find();
		$typeOb=D('Type');
		$optionStr=$typeOb->showOption($arr['typeid']);
		
		$this->assign('optionstr',$optionStr);
		
		$this->assign('arr',$arr);
		
		$this->display();
	}
	function usave(){
		//处理数据
		$arr=explode('|',$_POST['type']);
		$_POST['typefid']=$arr[0];
		$_POST['typeid']=$arr[1];
		unset($_POST['type']);
		$newsOb=D("News");
		$id=$_POST['id'];
		//指定条件
		//产生数据
		//保存
		$re=$newsOb->where("id=$id")
		           ->data($_POST)
		           ->save();
		//提示跳转
		if($re){
			$this->success("修改成功",U("Admin/News/oper"));
		}else{
			$this->error("修改失败",U("Admin/News/oper"));
		}
	}
	function del(){
		$newsOb=D("News");
		$id=$_GET['id'];
		$re=$newsOb->where("id=$id")
			       ->delete();//指定条件
		if($re){
			$this->success("删除成功",U("Admin/News/oper"));
		}else{
			$this->error("删除失败",U("Admin/News/oper"));
		}
	}
	function oper(){
		//获取所有的文章数据 news 使用Model类的方法select()
		$newsOb=M('News');
		$arr=$newsOb->order("id desc")->select();
		
		$this->assign('arr',$arr);
		$this->display();
	}
	function picture_add(){
		$this->display();
	}
	function product_category_add(){
		$mOb=M('goods_type');
		$typeArr=$mOb->where("fid=0")->select();
		$arr=$mOb->select();
		$this->assign('typeArr',$typeArr);
        $this->assign('arr',$arr);
        $re=$mOb->add($_POST);
        if($re){
           $this->success("添加成功",U("Admin/Product/product_category_add"));
        }
        $this->display();
	}
	function product_category(){
		
		$mOb=M('goods_type');
		$typeArr=$mOb->where("fid=0")->select();
		$this->assign('typeArr',$typeArr);
		$this->display();
	}
}